﻿//    Copyright 2014 LuoZhihui
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//      http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

#region  导入名称空间

using FluentNHibernate.Mapping;
using LotteryEngine.Model;

#endregion

namespace LotteryEngine.Repository.NHibernate.Mapping
{
	/// <summary>
	///     奖项映射
	/// </summary>
	public class PrizeMap : ClassMap<Prize>
	{
		public PrizeMap()
		{
			Table(@"LOTTERY_PRIZE");
			LazyLoad();
			Id(x => x.Id)
				.Column("ID")
				.CustomType("Int64")
				.Access.Property()
				.CustomSqlType("NUMBER")
				.Not.Nullable()
				.Precision(10)
				.GeneratedBy.Sequence("LOTTERY_PRIZE_SEQ");
			Map(x => x.PrizeName)
				.Column("PRIZE_NAME")
				.CustomType("String")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("VARCHAR2")
				.Not.Nullable()
				.Length(100);
			Map(x => x.PrizeCode)
				.Column("PRIZE_CODE")
				.CustomType("String")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("VARCHAR2")
				.Not.Nullable()
				.Length(100);
			Map(x => x.PrizePar)
				.Column("PRIZE_PAR")
				.CustomType("Double")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("NUMBER")
				.Precision(10)
				.Scale(4);
			Map(x => x.TotalCount)
				.Column("TOTAL_COUNT")
				.CustomType("Int64")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("NUMBER")
				.Not.Nullable()
				.Precision(10);
			Map(x => x.PrizeBlance)
				.Column("PRIZE_BLANCE")
				.CustomType("Int64")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("NUMBER")
				.Not.Nullable()
				.Precision(10);
			Map(x => x.IsActived)
				.Column("IS_ACTIVED")
				.CustomType("Boolean")
				.Access.Property()
				.Generated.Never()
				.CustomSqlType("NUMBER")
				.Not.Nullable()
				.Precision(1);

			HasMany(x => x.Configs)
				.Access.Property()
				.AsSet()
				.Cascade.None()
				.LazyLoad()
				.OptimisticLock()
				.Inverse()
				.Generic()
				.KeyColumns.Add("PRIZE_ID", mapping => mapping.Name("PRIZE_ID")
					.SqlType("NUMBER")
					.Not.Nullable());
			HasMany(x => x.Records)
				.Access.Property()
				.AsSet()
				.Cascade.None()
				.LazyLoad()
				.OptimisticLock()
				.Inverse()
				.Generic()
				.KeyColumns.Add("PRIZE_ID", mapping => mapping.Name("PRIZE_ID")
					.SqlType("NUMBER")
					.Not.Nullable());
		}
	}
}